package com.zx.mes.hyl.common.handler;


import com.zx.mes.hyl.common.exception.BaseException;
import com.zx.mes.hyl.common.msg.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * 全局异常捕获处理
 * @author hyl
 * @date 2017-12-16
 */
@ControllerAdvice("com.zx.mes")
@ResponseBody
public class GlobalExceptionHandler {

    private Logger logger= LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(BaseException.class)
    public BaseResponse baseExceptionHandler(HttpServletResponse response, BaseException ex){
        logger.error("全局RuntimeException捕获:"+ex.getMessage());
        return new BaseResponse(ex.getStatus(),ex.getMessage());
    }
}
